package com.hsy.linemoney.modules.my.mycustomer;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.deparse.dpframe.ui.android.widget.adapter.DPBaseAdapter;
import com.hsy.linemoney.R;
import com.hsy.linemoney.apiservice.LineMoneyContext;
import com.hsy.linemoney.utils.NumberUtil;

import java.util.List;
import java.util.Locale;

/**
 * Created by MartinKent on 2016/10/25.
 */

public class MyCustomerAdapter extends DPBaseAdapter<MyCustomerBean> {


    public MyCustomerAdapter(Context context) {
        super(context);
    }

    public MyCustomerAdapter(Context context, List<MyCustomerBean> data) {
        super(context, data);
    }

    @Override
    public CommonBaseViewHolder<MyCustomerBean> getHolder(int i) {
        return new ViewHolder();
    }

    private class ViewHolder extends CommonBaseViewHolder<MyCustomerBean> {

        protected View rootView;
        protected TextView title;
        protected TextView jfds;
        protected TextView lrjql;
        protected TextView jqds;

        @Override
        public View create(int i) {
            rootView = inflate(R.layout.my_customer_list_item);
            initView(rootView);
            return rootView;
        }

        @Override
        public void update(int i, MyCustomerBean bean) {
            String s = NumberUtil.numToString(bean.getLevel()).trim().toLowerCase();
            if (!Locale.CHINESE.equals(LineMoneyContext.getLocalLanguagePair().locale)) {
                if (s.endsWith("one")) {
                    s = s.substring(0, s.lastIndexOf("one")) + "first";
                } else if (s.toLowerCase().endsWith("two")) {
                    s = s.substring(0, s.lastIndexOf("two")) + "second";
                } else if (s.toLowerCase().endsWith("three")) {
                    s = s.substring(0, s.lastIndexOf("three")) + "third";
                } else if (s.toLowerCase().endsWith("five")) {
                    s = s.substring(0, s.lastIndexOf("five")) + "fifth";
                } else if (s.toLowerCase().endsWith("ty")) {
                    s = s.substring(0, s.lastIndexOf("ty")) + "ieth";
                } else {
                    s += "th";
                }
            }
            title.setText(context.getString(R.string.txt_di_x_ceng_tuan_dui_shang_juan_ji_fen, s));
            jfds.setText(String.valueOf(bean.getPoints()));
            lrjql.setText(String.valueOf(bean.getRatio()));
            jqds.setText(String.format(LineMoneyContext.getLocalLanguagePair().locale, "%.2f", Double.valueOf(bean.getRatio() * bean.getPoints()).floatValue()));
        }

        private void initView(View rootView) {
            title = (TextView) rootView.findViewById(R.id.title);
            jfds = (TextView) rootView.findViewById(R.id.jfds);
            lrjql = (TextView) rootView.findViewById(R.id.lrjql);
            jqds = (TextView) rootView.findViewById(R.id.jqds);
        }
    }
}
